package cn.chenlh.fx.common;

import javafx.application.Platform;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Utils {
    private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    public static void setTimeout(Runnable runnable, long delay) {
        scheduler.schedule(()->{
            Platform.runLater(runnable);
        }, delay, TimeUnit.SECONDS);
    }

    public static String fmt(String tmpl, Object... args) {
        if (args.length<1) {
            return tmpl;
        }
        String res = tmpl;
        for (Object arg : args) {
            res = res.replace("{}", arg.toString());
        }
        return res;
    }
}
